package org.LZQ.ShortLink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.LZQ.ShortLink.project.common.convention.result.Result;
import org.LZQ.ShortLink.project.common.convention.result.Results;
import org.LZQ.ShortLink.project.dto.req.ShortLinkGroupStatsAccessRecordReqDTO;
import org.LZQ.ShortLink.project.dto.req.ShortLinkGroupStatsReqDTO;
import org.LZQ.ShortLink.project.dto.req.ShortLinkStatsAccessRecordReqDTO;
import org.LZQ.ShortLink.project.dto.req.ShortLinkStatsReqDTO;
import org.LZQ.ShortLink.project.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import org.LZQ.ShortLink.project.dto.resp.ShortLinkStatsRespDTO;
import org.LZQ.ShortLink.project.service.LinkStatsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class LinkStatsController {
    private final LinkStatsService linkStatsService;

    /**
     * 访问单个短链接指定时间内监控数据
     * @param requestParam
     * @return
     */
    @GetMapping("/api/shortLink/project/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO requestParam){
        return Results.success(linkStatsService.oneShortLinkStats(requestParam));
    }
    /**
     * 访问分组短链接指定时间内监控数据
     */
    @GetMapping("/api/shortLink/project/stats/group")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkGroupStatsReqDTO requestParam) {
        ShortLinkStatsRespDTO shortLinkStatsRespDTO = linkStatsService.groupShortLinkStats(requestParam);
        return Results.success(shortLinkStatsRespDTO);
    }
    /**
     * 访问分页短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/shortLink/project/stats/access-record")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
        return Results.success(linkStatsService.shortLinkStatsAccessRecord(requestParam));
    }

    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/shortLink/project/stats/access-record/group")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordReqDTO requestParam) {
        return Results.success(linkStatsService.groupShortLinkStatsAccessRecord(requestParam));
    }

}
